//我的收藏！！！！！！！！！！！！！！！！！！！！！！！
var isover=0;
var currentIndex=1;//页码
$().ready(function(){
    aj();
});
var ajaxrunning="yes";//初始不能滚动
function aj(){
    if(isover===0){
        ajaxrunning="yes";
        $.ajax({
            type:"get",
            datatype: "json",
            url: mycollurl+"?userId="+id+"&pageSize=15&currentIndex="+currentIndex,
            success:function(data){
                if(data.Message==="没有数据"){
                    isover=1;//没有数据了
                    $("#waiting").css("display","none");
                    $("#nonews").css("display","block");
                }
                //有数据
                else{
                    if(data.Data&&data.Data.length>0){
                        if(data.Data.length<15){
                            $("#waiting").css("display","none");
                            $("#nonews").css("display","block");
                        }
                        var num=0;
                        for(var i=0;i<data.Data.length;i++){
                            num++;
                            if(num===data.Data.length){
                                ajaxrunning="no";
                            }
                            var unick1="";
                            if(data.Data[i].isHideName==1&&data.Data[i].userId!=id){
                                //unick1="匿名";
                            }else{
                                var thisReal="";
                                if(data.Data[i].realName){thisReal=" ("+data.Data[i].realName+")"}
                                if(data.Data[i].userId!=id){
                                    //unick1="<a href='otherpeoplepage.html?otherid="+data.Data[i].userId+"'>"+data.Data[i].userNick+thisReal+"</a>";
                                }else{
                                    //unick1="<a>"+data.Data[i].userNick+"</a>";
                                }
                            }
                            var reg=/([0-9/\-]*)/;
                            var tim=data.Data[i].cTime.match(reg)[0];
                            if(data.Data[i].cTime){
                                tim=getDateDiff(getDateTimeStamp(data.Data[i].cTime));
                            };
                            if(!tim){tim="刚刚"};
                            if(data.Data[i].type==1){
                                $("#questionlist").append("<div class='pagedlist_item cid"+data.Data[i].id+"'><div class='feed_item feed_type_question'><div class='EventHeader'><span class='senduser'>"+"新闻"+"&nbsp;&nbsp;"+tim+"</span> <span class='job'></span></div><h2><a class='question_link' href='newsdetail.html?newsid="+data.Data[i].contentId+"#fromuser="+id+"'>"+data.Data[i].title+"</a></h2><div class='ActionBar Question'><a class='WriteAnswer Button gofinish' id='cid"+data.Data[i].id+"'>取消收藏</a></div></div></div>")
                            }
                            else if(data.Data[i].type==2){
                                var tit=codetoface(data.Data[i].title);
                                $("#questionlist").append("<div class='pagedlist_item cid"+data.Data[i].id+"'><div class='feed_item feed_type_question'><div class='EventHeader'><span class='senduser'>"+"悬赏"+"</span> <span class='job'>  "+unick1+"&nbsp;&nbsp;"+tim+"</span></div><h2><a class='question_link' href='questiondetail.html?qid="+data.Data[i].contentId+"#fromuser="+id+"'>"+tit+"</a></h2><div class='ActionBar Question'><a class='WriteAnswer Button gofinish' id='cid"+data.Data[i].id+"'>取消收藏</a></div></div></div>")
                            }
                            else{
                                var tit=codetoface(data.Data[i].title);
                                var thisType="经验";
                                //if(data.Data[i].type==4){thisType="单身资源";}
                                //else if(data.Data[i].type==6){thisType="工作介绍";}
                                //else if(data.Data[i].type==7){thisType="租房买房";}
                                //else if(data.Data[i].type==8){thisType="项目信息";}
                                //else if(data.Data[i].type==9){thisType="人脉资源";}
                                //else if(data.Data[i].type==10){thisType="其他资源";}
                                $("#questionlist").append("<div class='pagedlist_item cid"+data.Data[i].id+"'><div class='feed_item feed_type_question'><div class='EventHeader'><span class='senduser'>"+thisType+"</span> <span class='job'>"+unick1+"&nbsp;&nbsp;"+tim+"</span></div><h2><a class='question_link' href='shareexppage.html?eid="+data.Data[i].contentId+"#fromuser="+id+"'>"+tit+"</a></h2><div class='ActionBar Question'><a class='WriteAnswer Button gofinish' id='cid"+data.Data[i].id+"'>取消收藏</a></div></div></div>")
                            }
                        }
                        //取消收藏功能部分
                        var cancelcoll=document.getElementsByClassName("gofinish");
                        if(cancelcoll.length===1){
                            cancelcoll[0].onclick=function(e){
                                var cid="";
                                var reg=/([0-9]+)/;
                                cid=cancelcoll[0].id.match(reg)[0];
                                var classname=cancelcoll[0].id;
                                document.getElementById("bg").style.display="block";
                                document.getElementById("bgm").style.display="block";
                                document.getElementById("nobtn").onclick=function(){
                                    document.getElementById("bg").style.display="none";
                                    document.getElementById("bgm").style.display="none";
                                };
                                document.getElementById("okbtn").onclick=function(){
                                    $.ajax({
                                        type:"post",
                                        datatype:"json",
                                        url:deletecollectionurl,
                                        data:{"collectionId":cid},
                                        success:function(data){
                                            document.getElementById("bg").style.display="none";
                                            document.getElementById("bgm").style.display="none";
                                            $("#questionlist div").remove();
                                        }
                                    })
                                }
                            }
                        }else{
                            for(var r1=0;r1<cancelcoll.length;++r1){
                                cancelcoll[r1].index=r1;
                                var cid="";
                                var reg=/([0-9]+)/;
                                cancelcoll[r1].onclick=function(e){
                                    cid= e.target.id.match(reg)[0];
                                    var classname=e.target.id;
                                    document.getElementById("bg").style.display="block";
                                    document.getElementById("bgm").style.display="block";
                                    document.getElementById("nobtn").onclick=function(){
                                        document.getElementById("bg").style.display="none";
                                        document.getElementById("bgm").style.display="none";
                                    };
                                    document.getElementById("okbtn").onclick=function(){
                                        $.ajax({
                                            type:"post",
                                            datatype:"json",
                                            url:deletecollectionurl,
                                            data:{"collectionId":cid},
                                            success:function(data){
                                                document.getElementById("bg").style.display="none";
                                                document.getElementById("bgm").style.display="none";
                                                console.log(data);
                                                console.log($("."+classname)[0]);
                                                $("."+classname).remove();
                                            }
                                        })
                                    }
                                }
                            }
                        }
                    }
                    else{
                        $("#waiting").css("display","none");
                        $("#nonews").css("display","block");
                    }
                }
            }
        })
    }
}
$(".mweb_modal_back_button").click(function(){
    if(document.referrer){
        history.go(-1);
    }else{
        location.href="setpage.html";
    }
});
$(window).scroll(function(){
    var mainheight=$(".home_feed").height();
    var windowheight=$(window).height();
    var what=$(".home_feed").offset().top;
    var chajuli=$(".home_feed").offset().top - $(window).scrollTop();
    var cz=windowheight-mainheight+50;
    if(chajuli<cz&&ajaxrunning==="no"){
        currentIndex++;
        aj();
    }
});